package com.hn.project.rqinspect.controller;

import com.hn.common.utils.SecurityUtils;
import com.hn.doc.xyj.annotation.Api;
import com.hn.framework.aspectj.lang.annotation.NotAuth;
import com.hn.framework.web.controller.BaseController;
import com.hn.framework.web.domain.AjaxResult;
import com.hn.project.rqinspect.domain.dto.CountCheckCenter;
import com.hn.project.rqinspect.domain.dto.CountCheckMemo;
import com.hn.project.rqinspect.domain.dto.LoginDto;
import com.hn.project.rqinspect.domain.vo.LoginVo;
import com.hn.project.rqinspect.service.SysUserService;
import com.hn.project.rqinspect.service.TaskCheckService;
import com.hn.utils.AssertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 描述: 授权
 *
 * @date 2019-11-19 10:16
 */
@Api("登录")
@RequestMapping("user")
@RestController
public class UserController extends BaseController {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private TaskCheckService taskCheckService;

    /**
     *  登录授权
     * @param code 授权code
     * @param corid 企业Id
     */
    @NotAuth
    @Api(value = "钉钉授权登录",result = LoginDto.class)
    @PostMapping("login")
    public AjaxResult login(@RequestBody LoginVo loginVo){
        String code = loginVo.getCode();
        return sysUserService.login(code);
    }

    @Api(value = "获取当前用户信息",result = LoginDto.class)
    @PostMapping("getUserInfo")
    public AjaxResult getUserInfo(){
        Integer userId = SecurityUtils.getUserId();
        return AjaxResult.success(sysUserService.getUserInfo(userId));
    }

    /**
     *  待办事宜 或 安全巡检备忘录
     *  1=巡检干部 2=网点负责人 3=系统管理员
     */
    @Api(value = "待办事宜或安全巡检备忘录",result = CountCheckMemo.class)
    @GetMapping("countCheckMemo")
    public AjaxResult countCheckMemo(Integer type){
        Integer userId = SecurityUtils.getUserId();
        AssertUtils.notNull(type,"type 必传");
        return AjaxResult.success(taskCheckService.countCheckMemo(type,userId));
    }

    /**
     *  巡检中心统计
     *  1=巡检干部 2=网点负责人 3=系统管理员
     */
    @Api(value = "巡检中心统计",result = CountCheckCenter.class)
    @GetMapping("countCheckCenter")
    public AjaxResult countCheckCenter(Integer type){
        Integer userId = SecurityUtils.getUserId();
        AssertUtils.notNull(type,"type 必传");
        return AjaxResult.success(taskCheckService.countCheckCenter(type,userId));
    }

}
